package miniBanco.Handler;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import javax.swing.JFrame;
import miniBanco.Core.ErroresBO;
import miniBanco.Dto.Errores;
import miniBanco.Gui.ErroresGrid;
import miniBanco.Mapper.ErroresDAO;

public class HandlerErrores {
	
	private static HandlerErrores instance = null;
	
	private JFrame jPopUpFrame;
	private ErroresGrid erroresGrid;
	private ErroresDAO erroresDAO;
	private ErroresBO erroresBO;
	private HandlerErrores() {
		erroresDAO = new ErroresDAO();
		erroresBO = new ErroresBO();
		erroresBO.setDao(erroresDAO);
	
	}

    public static HandlerErrores getInstance() {
      if(instance == null) {
         instance = new HandlerErrores();
      }
      return instance;
    }
    
   
	public ErroresGrid verErrores()
    {
    	erroresGrid = new ErroresGrid((ArrayList<Errores>) erroresBO.getAllErrores());
    	return erroresGrid;
    }
    
    public void closeErroresWindow()
    {
    	
    }

	public void OpenErroresPopup() {
		
    	erroresGrid = verErrores();
		jPopUpFrame = new JFrame();
		jPopUpFrame.setBounds(0,0,500,500);
		jPopUpFrame.add(erroresGrid);
		jPopUpFrame.setVisible(true);
		
		jPopUpFrame.addWindowListener
        (
            new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                	closeErroresWindow();
                }
            }
        );  
	}
	
	
}
